package com.zzptc.sky.baidudemo.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.zzptc.sky.baidudemo.utils.MyApplication;
import com.zzptc.sky.baidudemo.R;
import com.zzptc.sky.baidudemo.base.BaseActivity;
import com.zzptc.sky.baidudemo.utils.DanceWageTimer;
import com.zzptc.sky.baidudemo.views.RatingBar;
import com.zzptc.sky.baidudemo.views.RatingView;

import java.util.Random;

public class MainActivity extends BaseActivity implements View.OnClickListener {
    private RatingView rating_view;
    private TextView tv_number;
    private ImageView iv_user;
    private TextView tv_box;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);

        rating_view = (RatingView) findViewById(R.id.rating_view);
        tv_number = (TextView) findViewById(R.id.tv_number);
        iv_user = (ImageView) findViewById(R.id.iv_user);
        tv_box = (TextView) findViewById(R.id.tv_box);

        final int one = new Random().nextInt(10)+1;
        final int two = new Random().nextInt(10)+1;
        final int three = new Random().nextInt(10)+1;

        rating_view.addRatingBar(new RatingBar(one,showHighOrLow("清晰度",one)));
        rating_view.addRatingBar(new RatingBar(two,showHighOrLow("流畅度",two)));
        rating_view.addRatingBar(new RatingBar(three,showHighOrLow("安全度",three)));
        rating_view.show();

        rating_view.setAnimatorListener(new RatingView.AnimatorListener() {
            @Override
            public void onRotateStart() {

            }

            @Override
            public void onRotateEnd() {
                int num = (int) ((one*0.5+two*0.3+three*0.2)*10);
                long dwt = DanceWageTimer.getTotalExecuteTime(num,20);
                DanceWageTimer danceWageTimer = new DanceWageTimer(dwt,20,tv_number,num);
                danceWageTimer.start();
            }

            @Override
            public void onRatingStart() {

            }

            @Override
            public void onRatingEnd() {

            }
        });

        iv_user.setOnClickListener(this);
        tv_box.setOnClickListener(this);

        Intent intent = new Intent();
        intent.setAction("updateVersion");
        sendBroadcast(intent);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_main;
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            //用户图标
            case R.id.iv_user:
                Intent i = new Intent(MyApplication.getContext(),UserActivity.class);
                startActivity(i);
                break;
            case R.id.tv_box:
                Intent intent = new Intent(this,BaiBoxActivity.class);
                startActivity(intent);
                break;
        }
    }

    public String showHighOrLow(String name,int num){
        StringBuilder sb = new StringBuilder();
        sb.append(name);
        if (num>=8){
            sb.append("高");
        }else if (num>=5 && num <8){
            sb.append("中");
        }else if (num>=0 && num<5){
            sb.append("低");
        }

        return sb.toString();
    }
}
